package ua.tyran53red.contacts.channel;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import ua.tyran53red.StartDesktop;

public class ChannelTab extends JPanel {
	private static final long serialVersionUID = 1L;
	private JTable channelTable = null;
	private String channelData[][] = null;
	private String channelColumb[] = { "" };
	private JScrollPane jsbChannel = null;
	private HashMap<Integer, ChannelObject> channelMap = new ChannelImp().readXML();
	private int counter = 0;

	public ChannelTab(int width, int height) {
		setBackground(new Color(255, 255, 255));
		setLayout(null);
		channelData = new String [channelMap.size()][1];
		for (ChannelObject user: channelMap.values()) {
			channelData[counter][0] = user.getName();
			counter++;
		}
		channelTable = new JTable(channelData, channelColumb);
		channelTable.setBackground(new Color(238, 238, 238));
		channelTable.setRowHeight(50);
		channelTable.setSelectionBackground(new Color(255, 255, 255));
		channelTable.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent arg0) {
				StartDesktop.getInstance("", null).getUserPanel().setUser(channelMap.get(channelTable.getSelectedRow()).getName(), channelMap.get(channelTable.getSelectedRow()).getName(),channelMap.get(channelTable.getSelectedRow()).getUsersList(), false);
			}
		});
		jsbChannel = new JScrollPane(channelTable);
		jsbChannel.setBounds(5, 5, width - 15, height-100);
		add(jsbChannel);
	}
	
	public void repaint(int width, int height) {
		jsbChannel.setBounds(5, 5, width - 15, height - 100);
		this.repaint();
	}
}
